const gulp     = require('gulp'),
      conf     = require('../conf/conf'),
      rev      = require('gulp-rev'),
      path     = require('path'),
      del      = require('del'),
      usemin   = require('../lib/usemin'),
      uglify   = require('gulp-uglify');

module.exports = function () {

    if (DEVELOP) {
        return;
    }

    function clean() {
        del.sync(conf.build.root);
    }

    function usermin() {
        let useminOptions = {
            assetsDir         : conf.source.asset,
            outputRelativePath: '../asset/',
            css               : ['concat', rev()],
            js                : [uglify(), rev()]
        };

        gulp.src(path.resolve(conf.source.view, '**/*.jade'))
            .pipe(usemin(useminOptions))
            .pipe(gulp.dest(conf.build.view));
    }

    function font() {
        gulp.src(conf.source.asset + '/font/**')
            .pipe(gulp.dest(conf.build.asset + '/font/'));
    }

    function img() {
        gulp.src(conf.source.asset + '/img/**')
            .pipe(gulp.dest(conf.build.asset + '/img/'));
    }

    clean();
    usermin();
    font();
    img();
};